package com.example.mydesignmodule.yuanxing.yuanxing2;

/**
 * @author tgw
 * @date 2021/2/25
 * @describe
 */
class ShapeRunMain {

    public static void main(String[] args) throws CloneNotSupportedException {
        Shape shape = new Shape();
        shape.setAge("10");
        shape.setName("tgw1");
        shape.setArrayList("new A");
        shape.setArrayList("new B");
        System.out.println("浅拷贝开始了");
        System.out.println(shape.toString());

        Shape shapeCopy = (Shape) shape.clone();
        System.out.println("浅拷贝复制");
        System.out.println(shape.toString());
        System.out.println(shapeCopy.toString());
        System.out.println("浅拷贝改值");
        shapeCopy.setName("tgw浅拷贝复制");
        shapeCopy.setCopy("浅拷贝赋值 会影响 原本？");
        shapeCopy.setArrayList("new C"); //这个影响了 原本 list 值也会改变  因为 浅拷贝 只是参数地址引用 ，所以 list 也需要拷贝 克隆
        System.out.println(shape.toString());
        System.out.println(shapeCopy.toString());

        Shape shape1 = shape;
        System.out.println("改值");
        shape1.setName("tgw改值");
        System.out.println(shape.toString());
        System.out.println(shape1.toString());


        System.out.println("深拷贝开始了");
        DeepShape deepShape = new DeepShape();
        deepShape.setAge("101");
        deepShape.setName("tgw2");
        deepShape.setArrayList("new A1");
        deepShape.setArrayList("new B1");
        System.out.println(deepShape.toString());
        DeepShape deepShapeCopy = deepShape.deepCopy();
        deepShapeCopy.setName("tgw浅拷贝复制");
        deepShapeCopy.setCopy("浅拷贝赋值 会影响 原本？");
        deepShapeCopy.setArrayList("new C"); //这个影响了 原本 list 值也会改变  因为 浅拷贝 只是参数地址引用 ，所以 list 也需要拷贝 克隆
        System.out.println(deepShape.toString());
        System.out.println(deepShapeCopy.toString());
    }
}
